package keeto.com.vn.bms.network.task;

import java.io.IOException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetTypeUserRequest;
import keeto.com.vn.bms.network.response.GetTypeUserResponse;
import keeto.com.vn.bms.utils.BMSListener;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

public class TaskGetTypeUser extends AbstractTask{
	String authenKey;
	int Group_id;
	int pageLimit;
	int pageNumber;

	public TaskGetTypeUser(BMSListener listener, IBMSCore core, String authenKey, int Group_Id, int pageLimit, int pageNumber) {
		super(listener, core);
		this.authenKey = authenKey;
		this.Group_id = Group_Id;
		this.pageLimit = pageLimit;
		this.pageNumber = pageNumber;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException, IOException {
		GetTypeUserRequest request = new GetTypeUserRequest();
		request.setAuthenKey(authenKey);
		request.setGroupId(Group_id);
		request.setPageLimit(pageLimit);
		request.setPageNumber(pageNumber);
		GetTypeUserResponse reponse = protocol.getTypeUser(request);
		for (BMSListener mlistener : listener){
			mlistener.finishGetTypeUsers(reponse.getResultCode(), reponse.getResultMsg(), reponse.getRecordNumber(), reponse.getCountPage(),reponse.getGroupID(), reponse.getListUserModel());
		}
	}

	@Override
	public void timeoutCallback() {
		for (BMSListener mlistener : listener){
			mlistener.finishGetTypeUsers(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, "", 0, 0,0, null);
		}
	}

}
